import requests,time,re,xlrd
class front_Regist:
    def __init__(self):
# 当前页面获取tiny_token_reg
        self.ss = requests.session()
    def loading_Case(self):
        self.s = self.ss.get("http://192.168.34.146/TinyShop_v1.7/index.php?con=simple&act=reg")
        # print(self.s.text)
        x = self.s.text
        # 这是列表形式
        self.list_tiny_token_reg = re.findall(r"name='tiny_token_reg' value='(.+?)'/>",x)
        print(self.list_tiny_token_reg[0])
        print(len(self.list_tiny_token_reg[0]))
        print(type(self.list_tiny_token_reg[0]))
        time.sleep(1)
        for i in range(1,14):
            self.begin_Regist(i)
            time.sleep(0.5)
#   尝试注册请求
    def begin_Regist(self,i):
        book1 = xlrd.open_workbook(r'..\Data\Test_Data.xlsx')
        s = book1.sheets()[6]
        li1 = s.row_values(i)

        self.s2 = self.ss.post("http://192.168.34.146/TinyShop_v1.7/index.php?con=simple&act=reg_act",data={
            "email":li1[6],"password":li1[7],"repassword":li1[8],"verifyCode":li1[9],
            "tiny_token_reg":self.list_tiny_token_reg[0]
        })
        str1 = self.s2.text
        # print(str1)
        if "tiny_token_redirect" in str1:
            print("注册成功！！！")
            self.result1 = "注册成功"
        else:
            print("注册失败！！！")
            self.result1 = "注册失败"

        # 为报表最终测试结果做判定，以正确输出
        if li1[5] == self.result1:
            self.final_re = "用例通过"
        else:
            self.final_re = "用例未通过"

        file = r"..\Data\interface_test_report.txt"
        with open(file, "a+", encoding="utf-8") as f:
            f.write("%s,%s,%s,%s,%s,%s,%s\r" % (li1[0], li1[1], li1[2], li1[3], li1[5], self.result1, self.final_re))
# front_Regist().loading_Case()